//
//  MLZCommentsAndShow.m
//  MotherLover
//
//  Created by lanou on 16/1/7.
//  Copyright © 2016年 zj. All rights reserved.
//

#import "MLZCommentsAndShow.h"
#import "MLZShowViewController.h"
#import "MLZWebViewController.h"
#import "MLZCommunityViewController.h"
#import "MLZCommuniyDetalisViewController.h"
@interface MLZCommentsAndShow ()<MLZWebViewControllerDelegate,MLZCommunityViewControllerDelegate,UIScrollViewDelegate>
@property (strong, nonatomic)  UIScrollView *BaseScrollView;
@property (strong, nonatomic) MLZShowViewController *showController;
@property (strong, nonatomic) MLZCommunityViewController *commentsController;
@end

@implementation MLZCommentsAndShow

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

    [self addScrollview];
    self.navigationController.navigationBar.hidden= YES;
    

}
-(void)viewDidAppear:(BOOL)animated{

self.tabBarController.tabBar.hidden= NO;

}
- (void)addScrollview{
     self.BaseScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, KW, KH)] ;
    self.automaticallyAdjustsScrollViewInsets= NO;
    _BaseScrollView.delegate = self;
    _BaseScrollView.pagingEnabled = YES;
    _BaseScrollView.bounces = NO;
    _BaseScrollView.contentSize= CGSizeMake(KW*2, KH);
    _BaseScrollView.showsHorizontalScrollIndicator= NO;
    _BaseScrollView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:self.BaseScrollView];
    
    _showController = [[MLZShowViewController alloc]init];
    _showController.view.frame = CGRectMake(0, 0, KW, KH);
    _showController.delegate = self;
    [_BaseScrollView addSubview:_showController.view];

    _commentsController = [[MLZCommunityViewController alloc]init];
    _commentsController.view.frame = CGRectMake(KW, 0, KW, KH);
    _commentsController.delegate = self;
    [_BaseScrollView addSubview:_commentsController.view];
    //添加左右的button
    //添加左右的new 和hot选项
    UIButton *newbutton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    newbutton.backgroundColor = [UIColor blackColor];
    newbutton.tag = 3;
    newbutton.frame = CGRectMake(KW-130, 30, 30, 30);
    //[newbutton setTitle:@"今日" forState:(UIControlStateNormal)];
    [newbutton setBackgroundImage:[UIImage imageNamed:@"zuixin"] forState:(UIControlStateNormal)];
    [newbutton addTarget:self action:@selector(newbutton:) forControlEvents:(UIControlEventTouchUpInside)];
    newbutton.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:newbutton];
    UILabel *label = [[ UILabel alloc]initWithFrame:CGRectMake(KW-130, 64-2, 30, 2)];
    label.tag = 1;
    label.backgroundColor = [UIColor blackColor];
    [self.view addSubview:label];
    
    UILabel *label1 = [[ UILabel alloc]initWithFrame:CGRectMake(KW-70, 64-2, 30, 2)];
    label1.tag = 2;
    label1.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:label1];
    
    UIButton *hotbutton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    hotbutton.tag = 4;
    
    hotbutton.frame = CGRectMake(KW-70, 30, 30, 30);
    [hotbutton setBackgroundImage:[UIImage imageNamed:@"huati"] forState:(UIControlStateNormal)];
    

    [hotbutton addTarget:self action:@selector(newbutton:) forControlEvents:(UIControlEventTouchUpInside)];
    hotbutton.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:hotbutton];
    
    

}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    
    if(_BaseScrollView.contentOffset.x==0){
        
        UILabel *lable = (UILabel*)[self.view viewWithTag:1];
        lable.backgroundColor = [UIColor blackColor];
        UILabel *lable1 = (UILabel*)[self.view viewWithTag:2];
        lable1.backgroundColor = [UIColor whiteColor];
        
        
        
        
    }else {
        
        
        [_BaseScrollView setContentOffset:CGPointMake(KW, 0) animated:YES];
        UILabel *lable = (UILabel*)[self.view viewWithTag:2];
        lable.backgroundColor = [UIColor blackColor];
        UILabel *lable1 = (UILabel*)[self.view viewWithTag:1];
        lable1.backgroundColor = [UIColor whiteColor];
        
    }
    
    
    
    
    
    
}
-(void)newbutton:(UIButton*)button{
    
    if(button.tag ==3){
        
        
        [_BaseScrollView setContentOffset:CGPointMake(0, 0) animated:YES];
        UILabel *lable = (UILabel*)[self.view viewWithTag:1];
        lable.backgroundColor = [UIColor blackColor];
        UILabel *lable1 = (UILabel*)[self.view viewWithTag:2];
        lable1.backgroundColor = [UIColor whiteColor];
        
        
    }else if (button.tag==4){
        
        [_BaseScrollView setContentOffset:CGPointMake(KW, 0) animated:YES];
        UILabel *lable = (UILabel*)[self.view viewWithTag:2];
        lable.backgroundColor = [UIColor blackColor];
        UILabel *lable1 = (UILabel*)[self.view viewWithTag:1];
        lable1.backgroundColor = [UIColor whiteColor];
        
        
        
    }
    
    
    
    
    
    
    
    
}
-(void)jump:(NSString *)url{
    NSLog(@"%@",url);
    MLZWebViewController *webview= [[MLZWebViewController alloc]init];
      webview.webUrl= url;
   
  
    [self.navigationController pushViewController:webview animated:YES];




}

//帖子详情页
- (void)communityJumDetalis:(MLZPostsModel *)model{

    MLZCommuniyDetalisViewController *detalis = [[MLZCommuniyDetalisViewController alloc]init];
    detalis.model= model;
    [self.navigationController pushViewController:detalis animated:YES];


}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
